from django.db import models
from django.utils import timezone

from MirrorCore.models.User import User
from MirrorCore.models.Collection import Collection


class Article(models.Model):
    """
    主打收集
    author, 文章没删干净之前不让注销账号，
    title, 标题   不能为空
    brief, 简介
    collection 收集簿
    content, 文章内容
    tags, 标签
    create_time 创建时间
    update_time 修改时间
    """
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=100, default="未命名标题", blank=False)
    brief = models.CharField(max_length=100, blank=True, null=True)
    content = models.TextField(blank=True, null=True)

    collection = models.ForeignKey(Collection, blank=True, null=True, on_delete=models.SET_NULL, default=None, related_name="articles")
    create_time = models.DateTimeField(default=timezone.now)
    update_time = models.DateTimeField(auto_now=True)
    is_active = models.BooleanField(default=True)

    def __str__(self):
        return self.title


class Essay(models.Model):
    """
    主打记录
    author 作者
    title   标题可为空
    content 文本内容
    collection
    tags    标签
    create_time 创建时间
    update_time 修改时间
    """
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=50, blank=True,null=True)
    content = models.TextField(blank=True,default="")

    collection = models.ForeignKey(Collection, blank=True,null=True,on_delete=models.SET_NULL,default=None,related_name="essays",)

    create_time = models.DateTimeField(default=timezone.now)
    update_time = models.DateTimeField(auto_now=True)

    is_active = models.BooleanField(default=True)

    def __str__(self):
        return str(self.content)

